<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Learning About Backbone.js Model</title>

<script type="text/javascript"
	src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript"
	src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script type="text/javascript"
	src="http://documentcloud.github.com/backbone/backbone-min.js"></script>

<script type="text/javascript">

Person = Backbone.Model.extend({
	 initialize: function() {

		 console.log('initialize');

	//event change 
	  this.bind("change:name", function() {
	   console.log(this.get('name') + " is now the value for name");
	  });

	  
	  this.bind('error', function( model, error ) {
	   console.error(error);
	  });
	  
	 },

	 
	 defaults: {
	  name: "Bob Hope",
	  height: "unknown"
	 },

	 //throw exception if true
	 validate: function ( attributes ) {
	  if( attributes.name == 'Joe' ) {
	   return "Uh oh, you're name is Joe!";
	  }
	 }
	});


	 
	var person = new Person();
	person.set({name: "Joe", height:"6 feet"});
	 
	console.log(person.toJSON());

</script>

</head>
<body>


</body>
</html>